package top.xia17.plugins.fast.user.password;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * 固定的密码生成器
 *
 * @author xia17
 * @date 2022/1/17
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class StablePasswordGenerator implements PasswordGenerator {

    private final static String ID = "stable";

    /**
     * 默认密码
     */
    private String defaultPassword = "123456";


    @Override
    public String generate(String val) {
        return this.defaultPassword;
    }

    @Override
    public String getId() {
        return ID;
    }

    @Override
    public void setProperties(Map<String, String> properties) {
        if (properties == null) {
            properties = new HashMap<>(4);
        }
        String defaultPassword = properties.get("default-password");
        if (!StrUtil.isBlank(defaultPassword)) {
            this.defaultPassword = defaultPassword;
        }
    }
}
